package com.yong.opengl

import android.content.Intent
import android.opengl.GLSurfaceView
import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.yong.opengl.ui.DrawBgActivity
import com.yong.opengl.ui.DrawImgActivity
import com.yong.opengl.ui.DrawTriangleActivity
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {
    private var mGLView: GLSurfaceView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //mGLView = MyGLSurfaceView(R.layout.activity_main)

        setContentView(R.layout.activity_main)
        // Example of a call to a native method
        findViewById<TextView>(R.id.sample_text).text = stringFromJNI()

        //点击事件管理
        onClickManagement()
    }

    /**
     * 所有点击事件都放这里
     */
    private fun onClickManagement() {
        //绘制纯色背景
        draw_bg.setOnClickListener {
            val intent = Intent()
            intent.setClass(this, DrawBgActivity::class.java)
            startActivity(intent)
        }
        //绘制一个三角形
        draw_triangle.setOnClickListener {
            val intent = Intent()
            intent.setClass(this, DrawTriangleActivity::class.java)
            startActivity(intent)
        }
        //绘制一张图片
        draw_img.setOnClickListener {
            val intent = Intent()
            intent.setClass(this, DrawImgActivity::class.java)
            startActivity(intent)
        }
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    private external fun stringFromJNI(): String

    companion object {
        // Used to load the 'native-lib' library on application startup.
        init {
            System.loadLibrary("native-lib")
        }
    }
}